import QtQuick 2.0
import QtQuick.Window 2.0

Item {
    id: root
    width: Screen.width
    height: 900

    property bool isOpened: false
    property var lastDate: new Date
    property var lastMinDate: new Date

    property int restTime: 5 * 60
    property int workTime: 10*60

    Component.onCompleted: {
//        widget.show()
    }

    property var _IMGS: [
        "qrc:/images/01丨高抬手臂.gif",
        "qrc:/images/02丨踢三头肌.gif",
        "qrc:/images/03丨绿巨人.gif",
        "qrc:/images/04丨转腿筋.gif",
        "qrc:/images/05丨抬起膝盖.gif",
        "qrc:/images/06丨哈利路亚.gif",
        "qrc:/images/07丨拳击.gif",
        "qrc:/images/08丨桌子上俯卧撑.gif",
        "qrc:/images/09丨侧滑.gif",
        "qrc:/images/10丨跳蹲.gif",
        "qrc:/images/11丨椅子升降.gif",
        "qrc:/images/12丨步行.gif",
    ]

    Rectangle{
        id: rect
        width: parent.width
        height: root.height
        color: "white"

        Grid{
            id: grid
            columns: 4
            rowSpacing: 0
            columnSpacing: 0
            anchors.centerIn: parent

            // 1
            AnimatedImage{
                source: _IMGS[0]
            }

            AnimatedImage{
                source: _IMGS[1]
            }

            AnimatedImage{
                source: _IMGS[2]
            }

            AnimatedImage{
                source: _IMGS[3]
            }

            // 2
            AnimatedImage{
                source: _IMGS[4]
            }

            AnimatedImage{
                source: _IMGS[5]
            }

            AnimatedImage{
                source: _IMGS[6]
            }

            AnimatedImage{
                source: _IMGS[7]
            }

            // 3
            AnimatedImage{
                source: _IMGS[8]
            }

            AnimatedImage{
                source: _IMGS[9]
            }

            AnimatedImage{
                source: _IMGS[10]
            }

            AnimatedImage{
                source: _IMGS[11]
            }

        }
    }

    Timer{
        id: timer
        interval: 1000
        repeat: true
        running: true
        onTriggered: {
            var currentDate = new Date

            // 每 40 分钟 就提示 休息
            if(currentDate-lastDate > workTime*1000){
                widget.show()

                lastMinDate = new Date
                timerMin.restart()
                timer.stop()
            }
        }
    }

    Timer{
        id: timerMin
        interval: 500
        repeat: true
        onTriggered: {
            var currentDate = new Date

            //流逝的时间
            var timeLapse = Math.floor(currentDate-lastMinDate) / 1000

            if(restTime-timeLapse>=0){
            }
            else{
                // 休息 10 分钟， 结束， 继续工作
                lastDate = currentDate
                timerMin.stop()
                timer.restart()
                widget.hide()
            }
        }
    }
}
